/**
    @author: dt
    @date: 2025-06-23
    @description: 反转装饰器
*/
using UnityEngine;

namespace DLib.BehaviorTree
{
    /// <summary>
    /// 反转装饰器
    /// 将子节点的结果反转：
    /// - 成功变失败
    /// - 失败变成功
    /// - 运行中保持不变
    /// </summary>
    public class Inverter : DecoratorNode
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="child">要反转结果的子节点</param>
        public Inverter(Node child) : base(child) { }

        /// <summary>
        /// 评估子节点并反转结果
        /// </summary>
        /// <returns>反转后的执行状态</returns>
        protected override NodeState EvaluateChild()
        {
            NodeState childState = child.Evaluate();

            switch (childState)
            {
                case NodeState.Success:
                    // 子节点成功，反转器失败
                    state = NodeState.Failure;
                    break;
                case NodeState.Failure:
                    // 子节点失败，反转器成功
                    state = NodeState.Success;
                    break;
                case NodeState.Running:
                    // 子节点运行中，反转器运行中
                    state = NodeState.Running;
                    break;
            }

            return state;
        }
    }
} 